# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=rsync
pkgver=3.2.4
pkgrel=0
pkgdesc="A file transfer program to keep remote files in sync"
url="https://rsync.samba.org/"
arch="all"
license="GPL-3.0-or-later"
makedepends="perl acl-dev attr-dev popt-dev zlib-dev zstd-dev lz4-dev"
subpackages="$pkgname-doc $pkgname-openrc rrsync"
source="https://download.samba.org/pub/rsync/rsync-$pkgver.tar.gz
	rsyncd.initd
	rsyncd.confd
	rsyncd.conf
	rsyncd.logrotate
	"

# secfixes:
#   3.2.4-r0:
#     - CVE-2020-14387
#   3.1.2-r7:
#     - CVE-2017-16548
#     - CVE-2017-17433
#     - CVE-2017-17434
#   0:
#     - CVE-2020-14387

# delete the itemize test because it is flawed and depends on filesystem-specific behavior
prepare() {
	default_prepare
	rm testsuite/itemize.test

	# Prevent the aports version being used
	printf '#!/bin/sh\n\necho "#define RSYNC_GITVER RSYNC_VERSION" >git-version.h\n' >mkgitver
}

build() {
	# Force IPv6 enabled, upstream bug https://bugzilla.samba.org/show_bug.cgi?id=10715
	CFLAGS="$CFLAGS -DINET6" \

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-acl-support \
		--enable-xattr-support \
		--without-included-popt \
		--without-included-zlib \
		--disable-xxhash \
		--disable-openssl
		# xxhash and openssl support were implicitly disabled before via automagic
		# since nobody complained that those features were missing starting with 3.2.x
		# they cause errors unless they are expilcitly disabled. If you need those
		# features then open a MR
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 "$srcdir"/rsyncd.initd "$pkgdir"/etc/init.d/rsyncd
	install -Dm644 "$srcdir"/rsyncd.conf "$pkgdir"/etc/rsyncd.conf
	install -Dm644 "$srcdir"/rsyncd.confd "$pkgdir"/etc/conf.d/rsyncd
	install -Dm644 "$srcdir"/rsyncd.logrotate "$pkgdir"/etc/logrotate.d/rsyncd
}

rrsync() {
	pkgdesc="Restricted rsync, restricts rsync to a subdir declared in .ssh/authorized_keys"
	depends="rsync perl"
	arch="noarch"

	cd "$builddir"
	install -D -m 755 ./support/rrsync "$subpkgdir"/usr/bin/rrsync
}

sha512sums="
96318e2754fbddf84d16df671c721e577766969dfa415925c4dc1be2e4e60a51246623747a8aec0c6e9c0824e6aa7335235ccd07f3d6fd901f8cf28e2d6e91b6  rsync-3.2.4.tar.gz
b9bf1aa02f96e4294642ead5751bd529ca1267c08e83a16342fba5736c3a8ec89568feb11fb737e974cb1bee7e00e7a8898d25844892366c6167b9ea8d1e647c  rsyncd.initd
d91337cfb57e6e3b2a8ba1e24f7d851dd927bfc327da2212b9eb0acda0e1ca2f24987f6dcc4903eccc3bf170e0f115172b3cfa5a172700495296f26302c834d7  rsyncd.confd
3db8a2b364fc89132af6143af90513deb6be3a78c8180d47c969e33cb5edde9db88aad27758a6911f93781e3c9846aeadc80fffc761c355d6a28358853156b62  rsyncd.conf
e7ff164926785c4eff2ea641c7ce2d270b25f1c26d93a6108bb6ff2c0207a28ebfd93dca39596243446ce41aceaeae62fc2b34084eb9c9086fcdbc03a657eed8  rsyncd.logrotate
"
